<VirtualHost *:80>
    ServerName Symfony
    ServerAlias Symfony

    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined

    # used for http basic auth and oauth2 bearer token
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    SetEnv SYMFONY__DATABASE__USER {{ DBUSER }}
    SetEnv SYMFONY__DATABASE__PASSWORD {{ DBPASSWORD }}

    DocumentRoot {{ APPWEBROOT }}
    <Directory {{ APPWEBROOT }}>
        AllowOverride None
        Require all granted

        ## Start directives copied from standard Sf .htaccess
        DirectoryIndex app.php
        <IfModule mod_rewrite.c>
            RewriteEngine On

            RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
            RewriteRule ^(.*) - [E=BASE:%1]

            RewriteCond %{ENV:REDIRECT_STATUS} ^$
            RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

            RewriteCond %{REQUEST_FILENAME} -f
            RewriteCond %{REQUEST_URI} .*\.php
            # Need to add the phpfpm call here so that php files (including app_dev.php) are passed to FPM
            RewriteRule ^(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/%{REQUEST_FILENAME} [P,END]

            RewriteCond %{REQUEST_FILENAME} -f
            RewriteRule .? - [L]

            RewriteRule .? %{ENV:BASE}/app.php [L]

            # The main phpfpm call is added at the end to pass php requests through to FPM
            RewriteRule ^(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/%{REQUEST_FILENAME} [P,END]
        </IfModule>
        ## End directives copied from standard Sf .htaccess
    </Directory>
</VirtualHost>
